/**
 * 
 */
package com.lb.myeam.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jspsmart.upload.SmartUpload;

/**
 * @author 01053495-pc
 * 
 */
public class ServletDownload extends HttpServlet {

	private static final long serialVersionUID = 1L;

	private ServletConfig config;

	final public void init(ServletConfig config) throws ServletException {
		this.config = config;
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		String fileName = (String) request.getParameter("downloadFileName");
		SmartUpload mySmartUpload = new SmartUpload();
		try {
			// Smart下载三句核心代码
			mySmartUpload.initialize(config, request, response);
			mySmartUpload.setContentDisposition(null); // 下载时不在浏览器中显示
			mySmartUpload.downloadFile("/upload/" + fileName);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
